package com.learn.thread;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

/**
 * @author chenxin
 * @time 2017-02-19-10:12
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public class ThreadPoolTest {

    @Resource
    private ThreadPoolTaskExecutorWithMonitor testExecutor;

    @Test
    public void testThreadPoll() throws Exception{
        Assert.assertNotNull(testExecutor);
        for(int i = 0; i < 100; i++){
            testExecutor.execute(new Runnable() {
                @Override public void run() {
                    try {
                        System.out.println("test");
//                        long start = System.currentTimeMillis();
//                        while(true){
//                            long end = System.currentTimeMillis();
//                            if(end - start > 10){
//                                break;
//                            }
//                        }

//                        Thread.sleep(1000);
                    } catch (Exception e){
                        e.printStackTrace();
                    }
                }
            });

            Thread.sleep(1000);
        }

        Thread.sleep(10000);
    }
}
